package com.wtcrazy.controller;

import com.wtcrazy.entity.Admin;
import com.wtcrazy.entity.Comment;
import com.wtcrazy.entity.Record;
import com.wtcrazy.entity.User;
import com.wtcrazy.service.Impl.AdminServiceImpl;
import com.wtcrazy.utils.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminServiceImpl adminService;

    @ApiOperation("管理员登录")
    @PostMapping("/login")//
    public JsonResult login(@RequestBody Admin admin) {//@RequestBody将前端json转后台Java
        return adminService.login(admin);
    }

    @ApiOperation("Token认证")
    @GetMapping("/checkToken")
    public JsonResult checkToken(@RequestParam String Token) {
        return adminService.checkToken(Token);//Token要和缓存的key对应上
    }

    @ApiOperation("查询所有用户")
    @GetMapping("/getAllUsers")//【依赖于@RestController】
    public List<User> getAllUsers() {
        return adminService.getAllUsers();
    }

    @GetMapping("/FindPage")
    public Map<String, Object> findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                                        @RequestParam String username) {
        return adminService.findPage(pageNum, pageSize, username);
    }

    @GetMapping("/FindPost")
    public Map<String, Object> findPost(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                                        @RequestParam String title,
                                        @RequestParam String content) {
        return adminService.findPost(pageNum, pageSize, title, content);
    }


    @ApiOperation("删除用户")
    @DeleteMapping("/deleteUser")//
    public String deleteUser(@RequestParam String id) {//@GetMapping不支持@RequestBody
        adminService.deleteUser(id);
        return id;
    }


    @GetMapping("/GetView")
    public List<Object> getView() {
        return adminService.getView();
    }

    @GetMapping("/Getcomment")
    public List<Comment> getcomment() {
        return adminService.getcomment();
    }

    @GetMapping("/GetRecord")
    public List<Record> getRecord() {
        return adminService.getRecord();
    }

    @GetMapping("/FindComment")
    public Map<String, Object> findComment(@RequestParam Integer pageNum,
                                           @RequestParam Integer pageSize,
                                           @RequestParam String content) {
        return adminService.findComment(pageNum, pageSize, content);
    }

    @GetMapping("/FindOrder")
    public Map<String, Object> findOrder(@RequestParam Integer pageNum,
                                         @RequestParam Integer pageSize,
                                         @RequestParam String id) {
        Map<String, Object> result = adminService.findOrder(pageNum, pageSize, id);
        return result;
    }

}
